<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>${_title}</title>

    <!-- Bootstrap core CSS -->

    <link href="${_css}/bootstrap.min.css" rel="stylesheet">

    <link href="${_font}/css/font-awesome.min.css" rel="stylesheet">
    <link href="${_css}/animate.min.css" rel="stylesheet">

    <!-- Custom styling plus plugins -->
    <link href="${_css}/custom.css" rel="stylesheet">
    <link href="${_css}/icheck/flat/green.css" rel="stylesheet">


	<link type="text/css" href="${_js}/ueditor/themes/default/css/ueditor.css" rel="stylesheet"/>

    <script src="${_js}/jquery.min.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->

</head>


<body style="background: #F7F7F7;">
<div class="">
    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
                <div class="x_title">
                    <h2>担保方信息</h2>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content">

                    <form class="form-horizontal form-label-left" novalidate>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="title">新闻标题 <span class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                            	<input type="hidden" id="GuaranteeId" value="<#if item?exists>${item.id}</#if>"></hidden>
                                	<input id="name" class="form-control col-md-7 col-xs-12" value="<#if item?exists & item.name?exists>${item.name}</#if>"
                                	name="name" placeholder="公司名" required="required" type="text">
                            </div>
                        </div>
                                               
				</div>                        
                    </form>
                </div>
            </div>
        </div>
    </div>
	</div>

    <div class="row">
		<div class="col-md-12 col-sm-12 col-xs-12">
			<div class="x_panel">
				<div class="x_title">
		            <h2>公司介绍</h2>
		            <div class="clearfix"></div>
		        </div>
				<script id="editor1" type="text/plain" style="height:500px;"></script>
		    </div>
		</div>
	 </div>
    <div class="row">
		<div class="col-md-12 col-sm-12 col-xs-12">
			<div class="x_panel">
				<div class="x_title">
		            <h2>联系方式</h2>
		            <div class="clearfix"></div>
		        </div>
				<script id="editor2" type="text/plain" style="height:500px;"></script>
		    </div>
		</div>
	 </div>
	 						 	
    <div class="row">
		<div class="col-md-12 col-sm-12 col-xs-12">
		    <div class="ln_solid"></div>
		    <div class="form-group">
		        <div class="col-md-12 col-md-offset-5">
		            <button type="button" onclick="javascript:history.go(-1)" class="btn btn-primary">返回前一页</button>
		            <#if item?exists>
			            <button id="send" type="button" class="btn btn-success">修改</button>
			        <#else>
			            <button id="send" type="button" class="btn btn-success">保存</button>
		            </#if>
		        </div>
		    </div>			
		</div>
	</div> 

</div>

    <script src="${_js}/bootstrap.min.js"></script>
    <!-- bootstrap progress js -->
	<script src="${_js}/progressbar/bootstrap-progressbar.min.js" type="text/javascript"></script>
	<script src="${_js}/nicescroll/jquery.nicescroll.min.js" type="text/javascript"></script>
    <!-- icheck -->
    <script src="${_js}/icheck/icheck.min.js"></script>
    
	<script src="${_js}/custom.js" type="text/javascript"></script>
	<!-- dropzone -->
    <script src="${_js}/dropzone/dropzone.js" type="text/javascript" ></script>

    <script type="text/javascript" charset="utf-8" src="${_js}/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${_js}/ueditor/ueditor.all.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="${_js}/ueditor/lang/zh-cn/zh-cn.js"></script>
	<!-- PNotify -->
	<script src="${_js}/notify/pnotify.core.js" type="text/javascript"></script>
	<script src="${_js}/notify/pnotify.buttons.js" type="text/javascript"></script>
	<script src="${_js}/notify/pnotify.nonblock.js" type="text/javascript" ></script>
    <script type="text/javascript">
    	var ueditor1 = UE.getEditor('editor1');
    	var ueditor2 = UE.getEditor('editor2');
    	$(document).ready(function () {
       		var content = '<#if (item?exists) && (item.content?exists)>${item.content?string}</#if>';
    		ueditor1.addListener( 'ready', function() {
		    	ueditor1.setContent(content);
      		 });
       		var contact = '<#if (item?exists) && (item.contact?exists)>${item.contact?string}</#if>';
    		ueditor2.addListener( 'ready', function() {
		    	ueditor2.setContent(contact);
      		 });
        });
        
		/*$.ajaxSetup({
			headers: {'Content-Type': 'application/json;charset=UTF-8'}
		});*/     
		   
		var readFileIntoDataUrl = function (fileInfo) {
			var loader = $.Deferred(),
				fReader = new FileReader();
			fReader.onload = function (e) {
				loader.resolve(e.target.result);
			};
			fReader.onerror = loader.reject;
			fReader.onprogress = loader.notify;
			fReader.readAsDataURL(fileInfo);
			return loader.promise();
		};
        
		$(".btn-success").click(function(){
			var name = $.trim($("#name").val());
			var GuaranteeId = $.trim($("#GuaranteeId").val());
			var content = $.trim(ueditor1.getContent());
			var contact = $.trim(ueditor2.getContent());
			$.ajax({
	            type: 'POST',
	            dataType: 'JSON',
	            async:'false',
	            //headers: {'Content-type': 'application/json;charset=UTF-8'},
	            url: '/admin/guarantee/save',
	            data:{
	            "id":GuaranteeId,
				"name":name,
				"content":content,
				"contact":contact
				},
	            success: function(result){
	       		  if(result.code == -1){
	            		new PNotify({
			            	title: '操作提示',
			            	text:  result.msg,
			            	delay: 3e3,
			            	type: 'success'
			        	});
			        	window.location.href="/admin/guarantee/list";
	       		  }else{
						new PNotify({
			            	title: '操作提示',
			            	text:  result.msg,
			            	delay: 3e3,
			            	type: 'error'
			        	});
	       		  }
	            }
		    });
			
		});
    </script>
</body>

</html>